<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends MY_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	public function index(){
		$this->load->model('Welcome_Model','w');
		$data = $this->w->show();
		$data['book'] = $_SESSION['book'];
		$this->load->view('menu',$data);
	}

	public function user($worker = ''){
		$this->load->model('Worker_Model','w');
		
		if($w = $this->input->post()){//修改worker数据
			if($this->uri->segment(3)){
				if($this->w->update($w)){
					redirect(site_url('welcome/user/'.$this->uri->segment(3)));
				}
			}else{
				$this->load->view('user_n');
			}
		}else{//展示worker数据
			$data = $this->w->show($worker);
			if($worker){//展示某个worker
				$data['book'] = $_SESSION['book'];
				$this->load->view('user_s',$data);
			}else{//展示全部worker
				$data['book'] = $_SESSION['book'];
				$this->load->view('user',$data);
			}
		}
			
	}

	public function order($date = 'today'){
		$this->load->model('Attendance_Model','a');
		if($date === 'today'){
			$d =  date('Ymd');
		}else{
			$d = str_ireplace('-','',$date);
		}//获得需要查询的日期$data
		$data = $this->a->show($d);
		$data['book'] = $_SESSION['book'];
		$data['date'] = $date;
		$this->load->view('order',$data);
	}

	public function excel($worker){
		$this->load->model('Worker_Model','w');
		$data = $this->w->show($worker);
		if($worker){//展示某个worker
			$data['book'] = $_SESSION['book'];
			$this->load->view('user_e',$data);
		}
		header("Content-type:application/vnd.ms-excel"); 
		header("Content-Disposition:filename=".$data['info']->name.".xls");
	}

}
